#include "OpenGLRenderer.h"
#include <Windows.h>
#include <gl\gl.h>			// Header File For The OpenGL32 Library
#include <gl\glu.h>			// Header File For The GLu32 Library

#include "GLCubeRenderable.h"
OpenGLRenderer::OpenGLRenderer(void)
{
}


OpenGLRenderer::~OpenGLRenderer(void)
{
}

const bool OpenGLRenderer::initialise( const int width, const int height ) const
{
	resize(width, height);

	glShadeModel(GL_SMOOTH);							// Enable Smooth Shading
	glClearColor(1.0f, 0.0f, 0.0f, 0.5f);				// Black Background
	glClearDepth(1.0f);									// Depth Buffer Setup
	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing
	glDepthFunc(GL_LEQUAL);								// The Type Of Depth Testing To Do
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations
									// Initialization Went OK

	return true;
}

void OpenGLRenderer::shutdown( void ) const
{
}

void OpenGLRenderer::resize( const int width, const int height ) const
{
	glViewport(0,0,width,height);						// Reset The Current Viewport

	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
	glLoadIdentity();									// Reset The Projection Matrix

	float aspectRatio = width / ( height == 0 ?  1.f : static_cast< GLfloat >( height ) );

	// Calculate The Aspect Ratio Of The Window
	gluPerspective( 45.0f, aspectRatio, 0.1f, 100.0f );

	glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix
	glLoadIdentity();		
}

void OpenGLRenderer::renderScene( void ) const
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
	glLoadIdentity();									// Reset The Current Modelview Matrix

	GLCubeRenderable cube = GLCubeRenderable();
	cube.render( this );
}